№1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void FillRand(int A[], int n) {
    for (int i = 0; i < n; i++) {
        int h = (rand()%100)+1;
        if(i > 0){
            int check = 0;
            for(int j = 0; j < i; j++){
                if(A[j] == h){
                    check++;
                }
            }
            if(check == 0){
                A[i] = h;
            }else{
                i--;
            }
        }else{
            A[i] = h;
        }
    }
}

void Obnylenie(int A[], int n, int min_i, int min2_i){
    if(min_i < min2_i){
        int i = min_i+1;
        while(i < min2_i){
            A[i] = 0;
            i++;
        }
    }else{
        int i = min2_i+1;
        while(i < min_i){
            A[i] = 0;
            i++;
        }
    }
}


void PrintMas(int A[], int n) {
    for (int i = 0; i < n; i++) {
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    srand(time(NULL));
    int n = 20;
    int A[n];
    FillRand(A, n);
    cout << "Изначальный массив: " << endl;
    PrintMas(A, n);
    
    //ищим минимальный эллемент
    int min = 100, min_i;
    for(int i = 0; i < n; i++){
        if(A[i] < min){
            min = A[i];
            min_i = i;
        }
    }
    
    //ищим второй минимальный эллемент
    int min2 = 100, min2_i;
    for(int i = 0; i < n; i++){
        if((A[i] < min2) && A[i] != min){
            min2 = A[i];
            min2_i = i;
        }
    }
    
    Obnylenie(A, n, min_i, min2_i);
    cout << "Итоговый массив:\n";
    PrintMas(A, n);
}










№2
#include <iostream>
#include <cstdlib>
using namespace std;

void modifyA(int** A, int n){
    for(int i = 0; i < n; i++){
        int SUM = 0;
        int* temp = new int[A[i][0]];
        for(int j = 1; j <= A[i][0]; j++){
            SUM += A[i][j];
            temp[j-1] = A[i][j];
        }
        int l = A[i][0];
        delete[] A[i];
        A[i] = new int[l + 2];
        A[i][0] = l;
        A[i][l+1] = SUM;
        for(int j = 1; j <= l; j++){
            A[i][j] = temp[j-1];
        }
        delete[] temp;
    }
}

int main() {
    int n = 7;
    int** A = new int*[n];
    
    srand(time(NULL));
    for(int i = 0; i < n; i++){
        int size = rand() % 10 + 1;
        A[i] = new int[size + 1];
        A[i][0] = size;
        for(int j = 1; j <= size; j++){
            A[i][j] = rand() % 100;
        }
    }
    
    cout << "Исходный массив:" << endl;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= A[i][0]; j++){
            cout << A[i][j] << " ";
        }
        cout << endl;
    }
    
    modifyA(A, n);
    
    cout << "Модифицированный массив:" << endl;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= A[i][0] + 1; j++){
            cout << A[i][j] << " ";
        }
        cout << endl;
        delete[] A[i];
    }

    delete[] A;
    
    return 0;
}







№3
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

void PrintMas(int A[], int n) {
    for (int i = 0; i < n; i++) {
        cout << A[i] << " ";
    }
    cout << endl;
}

void FillRand(int A[], int n) {
    for (int i = 0; i < n; i++) {
        A[i] = rand()%1000;
    }
}

void InsertSort(int A[], int n){
    int temp, j;
    for(int i = 1; i < n; i++){
        temp = A[i]; j = i - 1;
        while(j >= 0 && temp > A[j]){
            A[j+1] = A[j];
            j = j - 1;
        }
        A[j+1] = temp;
    }
}

void binarySearch(int arr[], int size, int key, int& iterations) {
    int left = 0;
    int right = size - 1;
    int count = 0;

    while (left <= right) {
        count++;
        int mid = left + (right - left) / 2;

        if (arr[mid] == key) {
            iterations = count;
        }
        else if (arr[mid] < key) {
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }

    iterations = count;
}

void PereborSearch(int A[], int size, int key, int& iterations){
    int i = 0;
    while(A[i] != key){
        i++;
        iterations++;
    }
}


int main(){
    int n1 = 100, n2 = 1000;
    int A[n1], B[n2];
    int key;
    srand(time(NULL));
    FillRand(A, n1);
    key = A[rand()%n1]; // эллемент который будем искать
    InsertSort(A, n1);
    int iterations1 = 0, iterations2 = 1;
    binarySearch(A, n1, key, iterations1);
    PereborSearch(A, n1, key, iterations2);
    
    cout << setw(30) << "Поиск эллемента бинарным способом и перебором" << endl;
    cout << setw(25) << "Бинарный способ" << setw(25) << "Перебор" << endl;
    cout << setw(8) << iterations1 << setw(23) << iterations2 << endl;
    
    FillRand(B, n2);
    key = A[rand()%n2]; // эллемент который будем искать
    InsertSort(B, n2);
    iterations1 = 0, iterations2 = 1;
    binarySearch(B, n2, key, iterations1);
    PereborSearch(B, n2, key, iterations2);
    cout << setw(8) << iterations1 << setw(24) << iterations2 << endl;
}
